export function paramOptimize(fn: (...args: any[]) => any): any {
    return (target: any, key: string, decorators: any): any => {
        let pastValue = decorators.value;
        function newValue(...args: any[]) {
            // @ts-ignore
            let temp = pastValue.bind(this);
            return temp(...fn(...args));
        }
        decorators.value = newValue;
    }
}
export function catchErr(res: any = undefined): any {
    return (target: any, key: string, decorators: any) => {
        let pastValue = decorators.value;
        function newValue(...args: any[]) {
            // @ts-ignore
            let temp = pastValue.bind(this);
            try {
                return temp(...args); 
            } catch (error) {
                return res;
            }  
        }
        decorators.value = newValue;
    }
}

export function catchReturn(func: (...args: any[]) => void): any {
    return (target: any, key: string, decorators: any): any => {
        let pastValue = decorators.value;
        function newValue(..._args: any[]) {
            // @ts-ignore
            let temp = pastValue.bind(this);
            let _result = temp(..._args);
            func(..._args, _result)
            return _result;   
        }
        decorators.value = newValue;
    };
}
